package online.shiming.file.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import online.shiming.file.mapper.UserMapper;
import online.shiming.file.pojo.User;
import online.shiming.file.service.UserService;
import online.shiming.file.util.DataDo;

/**
 * @author ShiMing
 * @version 1.0
 * @name FileServiceImpl
 * @description TODO
 * @date 2020/11/13
 */

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    @Override
    public DataDo<?> login(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("name", user.getName()).eq("password", user.getPassword());
        User existUser = userMapper.selectOne(wrapper);
        if (null == existUser) {
            return DataDo.error("账号或密码错误，请检查后登录");
        } else {
            return DataDo.ok(existUser);
        }
    }

    @Override
    public DataDo<?> register(User user) {
        return DataDo.ok(userMapper.insert(user));
    }

    @Override
    public User selectUserById(String id) {
        return userMapper.selectById(id);
    }

}
